import requests
from bs4 import BeautifulSoup

# 百度热榜的URL
url = 'https://top.baidu.com/board?tab=realtime'

# 发送HTTP请求
response = requests.get(url)

# 检查请求是否成功
if response.status_code == 200:
    # 使用BeautifulSoup解析HTML内容
    soup = BeautifulSoup(response.text, 'html.parser')

    # 查找包含热榜的元素
    hot_list = soup.find_all('div', class_='category-wrap_iQLoo horizontal_1eKyQ')

    # 打印每个热榜条目
    for item in hot_list:
        title = item.find('div', class_='c-single-text-ellipsis').get_text()
        index = item.find('div', class_='hot-index_1Bl1a').get_text()
        print(f'排名：{index}, 标题：{title}')
else:
    print(f'请求失败，状态码：{response.status_code}')
